﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DHNetSDK;
using DLLTest.OpertionClass;

namespace DLLTest
{
    public partial class frm_Wall : Form
    {
        public frm_Wall()
        {
            InitializeComponent();
        }

        private void frm_Wall_DoubleClick(object sender, EventArgs e)
        {
            closeForm();
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            closeForm();
        }

        /// <summary>
        /// 关闭窗口
        /// </summary>
        private void closeForm()
        {
            if (this.Tag != null &&
                this.Tag.ToString().Split(',').Length == 7)
            {
                // a. 先停止上墙窗口中的视频
                string[] leafTag = this.Tag.ToString().Split(',');
                DHClient.DHStopRealPlay(Convert.ToInt32(leafTag[6])); // 停止实时监控，需要传递实时监控句柄

                // b. 再播放所选窗口中的视频
                PanelOpertion.SelectedPanel.Tag = this.Tag.ToString().Substring(0,
                    this.Tag.ToString().LastIndexOf(',')); // 去 realPlayHandle

                string[] selectedPanelTag = PanelOpertion.SelectedPanel.Tag.ToString().Split(',');
                int pRealPlayHandle = DHClient.DHRealPlay(int.Parse(selectedPanelTag[4]),
                    Convert.ToInt32(selectedPanelTag[5]), PanelOpertion.SelectedPanel.Handle); //只取数据不播放

                PanelOpertion.SelectedPanel.Tag = string.Format("{0},{1}", PanelOpertion.SelectedPanel.Tag, pRealPlayHandle); // 得到最新的 SelectedPanelTag: ip,port,user,pwd,loginID,channel,realPlayHandle
            }

            // c. 关闭窗口
            this.Close();
        }
    }
}
